package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringConstructContentBean;
import com.cloudsigns.factorymanager2.engineering.customview.SpinerPopWindow;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/3/29.
 */

public class PopWindowAdapter  extends BaseAdapter {
    private Context context;
    private List<String> datas = new ArrayList<String>();
    private LayoutInflater inflater;
    private String tag = "";

    public PopWindowAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setData(List<String> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_spinner_pop_window, null);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvName.setText(datas.get(position));
        return convertView;
    }


    private class ViewHolder {
        private TextView tvName;
    }
}
